package com.example.a2207_zh

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.Handler
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.SPUtils
import com.example.a2207_zh.databinding.ActivityWelcomeBinding
import com.example.a2207_zh.mvvm.BaseViewActivity
import java.util.Timer
import kotlin.concurrent.timerTask

/**
 * 欢迎页--闪屏页----广告页
 */
class WelcomeActivity : BaseViewActivity<ActivityWelcomeBinding>() {
    lateinit var timer: Timer
    val handler = Handler()
    var time = 3
    override fun getLayout(): Int  = R.layout.activity_welcome

    override fun initView() {
        timer = Timer()
        timer.schedule(timerTask {
                                 handler.post {
                                     binding.djs.text = "${time}秒"
                                     time--
                                     if(time==0){
                                         //定时器取消，当前界面结束
                                         timer.cancel()
                                         finish()
                                         //判断是否登录过--跳转到指定页面
                                         if(SPUtils.getInstance().getString("token").isNotEmpty()){
                                             ARouter.getInstance().build("/app/MainActivity").navigation()
                                         }else{
                                             ARouter.getInstance().build("/app/LoginActivity").navigation()
                                         }

                                     }
                                 }
        },0,1000)
    }

    override fun initData() {

    }

}